﻿package igz.fleaxy.ui.calendar 
{
	import flash.display.Shape;
	import flash.display.Sprite;
	import igz.fleaxy.ui.text.LabelUi;
	import igz.fleaxy.util.DateTimeTypes;
	import igz.fleaxy.util.DateTimeUtil;
	import igz.fleaxy.util.ObjectUtil;
	/**
	 * ...
	 * @author 
	 */
	public class CalendarWeekDayUi extends Sprite{
		
		protected var _Bg : Shape;
		protected var _Text : LabelUi;
		
		protected var _Settings:Object = { "dayWeekWidth" : 23
										  ,"dayWeekHeight" : 23
										  ,"dayWeekBgColor" : 0xff0000
										  ,"dayWeekBgAlpha" : 1
										  ,"dayWeekLabelStyle" : "defaultText"
										  ,"labelWeekDay" : null
										};
		
		public function get $Settings():Object {
			return _Settings;
		}
		
		public function CalendarWeekDayUi( p_weekDay : Number, p_settings : Object = null )  {
			var _Date : Date = new Date();
			
			ObjectUtil.$Merge(p_settings, _Settings);
			
			_Bg = new Shape();
			addChild( _Bg );
			
			var weekDay:String;
			if ((_Settings["labelWeekDays"] as String).split(",").length == 7)
			{
				 var weekDays:Array = (_Settings["labelWeekDays"] as String).split(",");
				 weekDay = weekDays[p_weekDay - 1];;
			} else {
				weekDay = DateTimeUtil.$GetValue( new Date( _Date.getFullYear(), _Date.getMonth(), p_weekDay ), DateTimeTypes.WEEK_DAY_SHORT );
			}
			
			_Text = new LabelUi( weekDay, _Settings["dayWeekLabelStyle"] );
			addChild( _Text );
			
			_Draw();
		}
		
		protected function _Draw() : void {
			_Bg.graphics.clear();
			_Bg.graphics.beginFill( _Settings["dayWeekBgColor"], _Settings["dayWeekBgAlpha"] );
			_Bg.graphics.drawRect( 0, 0, _Settings["dayWeekWidth"], _Settings["dayWeekHeight"] );
			_Bg.graphics.endFill();
			
			_Text.x = width - _Text.width >> 1;
			_Text.y = height - _Text.height >> 1;
		}
		
		public function $setStyleDayWeek(p_style:String):void {
			_Text.$StyleName = p_style;
		}
		
	}

}